﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace LabMS.Web.BaseData
{
    public partial class ClassData : Base.BasePage
    {
        ExtendBLL.Class EC = new ExtendBLL.Class();
       
        protected void Page_Load(object sender, EventArgs e)
        {
            strPageUserType.Add("mana");
            strPagePrivilege.Add("BJSJ");

            if (!IsPostBack)
            {
                InitBind();
            }
            btnDel.Attributes.Add("onclick","return confirm('你确定要删除?');");
        }

        /// <summary>
        /// 页面初始化绑定
        /// </summary>
        protected void InitBind()
        {   
            gvClass.DataSource =EC.GetListByStr().Tables[0].DefaultView; 
            gvClass.DataBind();
        }

        /// <summary>
        /// 导出到EXCEL 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExecl_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDel_Click(object sender, EventArgs e)
        {
            bool success = false;
            CheckBox cb;
            for (int i = 0; i < gvClass.Rows.Count; i++)
            {
                cb =(CheckBox)gvClass.Rows[i].FindControl("Chk");
                if (cb.Checked)
                {
                    int ID = int.Parse(gvClass.DataKeys[i].Value.ToString());
                    try
                    {
                        EC.Delete(ID);
                        success = true;
                    }
                    catch
                    {
                        Common.JShelper.JSAlert(this.Page, "", "该班级有学生信息，不能删除！");
                    }
                }
            }
            if (success == true)
            {
                Common.JShelper.JSAlert(this.Page, "", "删除成功！");
                InitBind();
            }
            else
            {
                Common.JShelper.JSAlert(this.Page,"","删除失败！");
            }
        }

        protected void gvClass_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
                //e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");
                e.Row.Attributes["style"] = "Cursor:pointer";
            }
        }

        protected void gvClass_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvClass.PageIndex = e.NewPageIndex;
            InitBind();
        }
    }
}
